const MAX_POINTS :u32 = 1000000;

fn main() {
    //1、变量定义
    //定义变量用let，如果变量没有用mut，那么是不可变的
    //let name: type 
    let a = 1;
    //let a:u32 = 1;
    println!("a = {}", a);

    //let b:u32 = 1;
    let mut b: u32 = 1;
    println!("b = {}", b);

    b = 2;
    println!("b = {}", b);

    //2、隐藏
    let b: f32 = 1.1;
    println!("b = {}", b);

    //3、常量
    println!("MAX_POINTS = {}", MAX_POINTS);

    //bool
    let is_true: bool = true;
    println!("is_true = {}", is_true);

    let is_false = false;
    println!("is_false = {}", is_false);

    //char 在rust里面，char是32位的
    let a:char = 'a';
    println!("a = {}", a);

    let b = '你';
    println!("b = {}", b);
    
    //i8, i16, i32, i64, u8, u16, u32, u64, f32, f64
    let c: i8 = -111;
    println!("c = {}", c);

    let c:i32 = 98_222; //十进制
    let c:i32 = 0xff;   //十六进制
    let c:i32 = 0o77;   //八进制
    let c:i32 = 0b1111_0000;    //二进制
    let c:u8 = b'A';    //字符（u8）

    let mut c:u8 = 255;

    //c = c + 1; //整型溢出，debug模式下运行报错，release模式下运行为0

    println!("c :u8 溢出 = {}", c);

    let d: f32 = 0.0009;
    println!("d = {}", d);

    //自适应类型isize, usize
    println!("max = {}", usize::max_value());

    //数组
    //[Type; size] , size 也是数组类型的一部分
    let arr: [u32; 5] = [1, 2, 3, 4, 5];
    let arr1: [u32; 3] = [1, 2, 3];
    println!("arr = {:?}", arr);
    println!("arr1[0] = {}", arr1[0]);
    println!("arr1.len() = {}",arr1.len());

    // Rust存在数组越界检查
    // painc at runtime
    // let index = 3;
    // println!("arr1[3] = {}", arr1[index]);

    //元组
    //let tup: (i32, f32, char) = (-3, 3.69, '好');
    let tup = (-3, 3.69, '好');
    println!("tup = {:?}",tup);
    println!("tup.0 = {}",tup.0);
    
    //解构
    let (x, y, z) = tup;
    println!("x = {}", x);
    println!("y = {}", y);
    println!("z = {}", z);

    println!("Hello, world!");

    let s = String::from("121212");

    println!("{}",&s[0..2]);
}
